(function(window){
	var Index_notebook = {
		data:{},
		init: function(data){
			Index_notebook.data=data;
			Index_notebook.bindEvent();
			//alert("show_eng_words_index");
			//console.log(show_eng_words_index);
			Index_notebook.show_eng_words(show_eng_words_index);
			if($(".eng_words_new").length>0){
				Index_notebook.show_eng_words();
				$("#konw_it").show();
			 }
			 hiApp.active_toolbar('notebook');
			
        },
		
		show_eng_words:function(){
			var index=show_eng_words_index;
			//console.log(show_eng_words_index);
			$(".eng_words_new").hide();
			$(".eng_words_new").eq(index).attr("eng_words_show","0");
			$(".remember_0").eq(index).show();
			$(".remember_0").eq(index).attr("eng_words_show","1");
		},
		
		show_chinese:function(){
			//console.log($(this).parent().text());
			$(this).parent().parent().find(".chinese").slideToggle();
		},
		
		show_next:function(){
			var all_words=$(".eng_words_new").length-2;
			if(show_eng_words_index>all_words){
				Index_notebook.complete();
				return false;	
			}
			show_eng_words_index++;
			Index_notebook.show_eng_words();
			Index_notebook.show_konw_it();
			
		},
		show_prev:function(){
			if(show_eng_words_index==0){
				return false;	
			}
			show_eng_words_index--;
			Index_notebook.show_eng_words();
			Index_notebook.show_konw_it();
			
		},
		
		show_konw_it:function(){
			$("#konw_it").show();
			$("#next_it").hide();
		},
		
		show_next_bnt:function(){
			$("#konw_it").hide();
			$("#next_it").show();
		},
		
		do_not_remember:function(){
			$("[eng_words_show='1']").find(".show_chinese").trigger(hiApp.device.click);
			Index_notebook.show_next_bnt();			
		},
		
		i_remember:function(){
			var id=$("[eng_words_show='1']").attr("data-id");
			var warning_num=Number($("#word_warning").text())-1;
			var success_num=Number($("#word_success").text())+1;
			$("#word_success").text(success_num);
			$("#word_warning").text(warning_num);
			$.post(hiApp.params.base_url+"/Index/remember/",{id:id});
			if(warning_num==0){
				Index_notebook.complete();
				return false;
			}
			Index_notebook.show_next();
			Index_notebook.show_konw_it();
			
		},
		
		complete:function(){
			dialog("恭喜你，学完了今天的单词");
		},
		afterShow:function(){
			//$("#next_it").hide();
		},
		
		bindEvent: function(){
            var bindings = [
			{
                element: '.show_chinese',
                event: hiApp.device.click,
                handler: this.show_chinese
            },
			{
                element: '#word-button-new',
                event: hiApp.device.click,
                handler: this.do_not_remember,
            },
			{
                element: '#word-button-complete',
                event: hiApp.device.click,
                handler: this.i_remember,
            },
			{
                element: '#word-button-prev',
                event: hiApp.device.click,
                handler: this.show_prev,
            },
			{
                element: '#word-button-next',
                event: hiApp.device.click,
                handler: this.show_next,
            }
			];
			 bindEvents(bindings);
        },
		
    };
		
	window.BoxEng_Index_notebookCtrl = Index_notebook;
						
})(window);